package com.ruoyi.rel.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.rel.domain.RelBankFile;
import com.ruoyi.rel.service.IRelBankFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题库文件关联Controller
 * 
 * @author ruoyi
 * @date 2024-09-30
 */
@RestController
@RequestMapping("/rel/rel")
public class RelBankFileController extends BaseController
{
    @Autowired
    private IRelBankFileService relBankFileService;

    /**
     * 查询题库文件关联列表
     */
    @PreAuthorize("@ss.hasPermi('rel:rel:list')")
    @GetMapping("/list")
    public TableDataInfo list(RelBankFile relBankFile)
    {
        startPage();
        List<RelBankFile> list = relBankFileService.selectRelBankFileList(relBankFile);
        return getDataTable(list);
    }

    /**
     * 导出题库文件关联列表
     */
    @PreAuthorize("@ss.hasPermi('rel:rel:export')")
    @Log(title = "题库文件关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RelBankFile relBankFile)
    {
        List<RelBankFile> list = relBankFileService.selectRelBankFileList(relBankFile);
        ExcelUtil<RelBankFile> util = new ExcelUtil<RelBankFile>(RelBankFile.class);
        return util.exportExcel(list, "题库文件关联数据");
    }

    /**
     * 获取题库文件关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('rel:rel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(relBankFileService.selectRelBankFileById(id));
    }

    /**
     * 新增题库文件关联
     */
    @PreAuthorize("@ss.hasPermi('rel:rel:add')")
    @Log(title = "题库文件关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RelBankFile relBankFile)
    {
        return toAjax(relBankFileService.insertRelBankFile(relBankFile));
    }

    /**
     * 修改题库文件关联
     */
    @PreAuthorize("@ss.hasPermi('rel:rel:edit')")
    @Log(title = "题库文件关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RelBankFile relBankFile)
    {
        return toAjax(relBankFileService.updateRelBankFile(relBankFile));
    }

    /**
     * 删除题库文件关联
     */
    @PreAuthorize("@ss.hasPermi('rel:rel:remove')")
    @Log(title = "题库文件关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(relBankFileService.deleteRelBankFileByIds(ids));
    }
}
